<?php
require_once 'PDO.class.php';

class Category extends PDOClass{

	public function __construct()
	{
		parent::__construct();
	}
	
	public function o_fListcategories()
	{
		
		$o_Categories = new stdClass();
		$sql="SELECT * FROM wof_cat ORDER BY cat_id ASC";
		$statement = $this->db->query($sql);
		$statement->execute();
		$statement->setFetchMode(PDO::FETCH_OBJ);	
		
		$i= 0;	
		while ($row = $statement->fetch())
		{
			$a_Cat = array();
			$a_Cat['id'] = $row->cat_id;
			$a_Cat['name'] = $row->cat_name;
			$o_Categories->{$i} =$a_Cat;
			$i++;
		}
		return $o_Categories;
	}
	
	public function o_fGetCatById($id)
	{
		$o_Quiz = new stdClass();
		$sql="SELECT * FROM wof_cat WHERE cat_id= ?";
		$statement = $this->db->prepare($sql);
		$statement->execute(array($id));
		$statement->setFetchMode(PDO::FETCH_OBJ);
		return $statement->fetch();
	}
	
	public function b_fUpdateCate($a_Cate)
	{
		$sql = "
				UPDATE wof_cat
				SET cat_name=? WHERE cat_id = ?";
		$statement = $this->db->prepare($sql);
		return $statement->execute($a_Cate);
	}
	
	public function b_fInsertCate($a_Data)
	{
		$sql = "
		INSERT INTO wof_cat (cat_name)
		VALUES (?)";
		$statement = $this->db->prepare($sql);
		return $statement->execute($a_Data);
	}
	
	public function o_fDeleteCateById($id)
	{
		$sql2="DELETE FROM wof_quiz WHERE quiz_cat_id=".$id."";
		$statement2 = $this->db->prepare($sql2);
		$statement2->execute();
		
		$sql="DELETE FROM wof_cat WHERE cat_id=".$id."";
		$statement = $this->db->prepare($sql);
		return $statement->execute();
	}
	
}

$o_CategoryModel = new Category();
?>
